﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    public class BattleCardConfig : Entity
    {
        public static BattleCardConfig Single
        {
            get
            {
                if (single == null)
                {
                    single = new BattleCardConfig();
                    single.Awake();
                }
                return single;
            }
        }
        private static BattleCardConfig single;
        public BattleCard[] cards;
        public void Awake()
        {
            cards = Game.Scene.GetComponent<ConfigComponent>().GetAll<BattleCard>();
        }
        public BattleCard GetCard(int index)
        {
            return CardClone(cards[index]);
        }

        public BattleCard GetCard(string InfoFlag)
        {
            foreach (var a in cards)
            {
                if (a.InfoFlag == InfoFlag)
                {
                    return CardClone(a);
                }
            }
            return null;
        }

        private BattleCardConfig()
        {

        }

        BattleCard CardClone(BattleCard card)
        {
            BattleCard Clone = MongoHelper.FromBson<BattleCard>(MongoHelper.ToBson(card));
            MongoHelper.TryAwake(Clone);
            return Clone;
        }
    }
}
